﻿<!--#include virtual="/Common/Config.asp" -->
<!--#include virtual="/Common/conn.asp" -->
<!--#include virtual="/Common/MD5.asp" -->
<!--#include virtual="/Common/Function.asp" -->
<%

Dim UserName
Dim UserPassword		
Dim email				
Dim Member_Type					



Dim Reg_IP	

UserName = Request.Form("UserName")
patrn = "^[-_a-zA-Z0-9\u4e00-\u9fa5]{2,32}$" '4个至32(中文 a-z0-9 _-字符)

If  RegExpTest(patrn,UserName) = False  Then 
	AlertBox "用户名只能是中、英文、数字，下划线及短横线中的组合!","javascript:history.go(-1)"
End If 


Call Check_Length(UserName,20,1,"用户名")

UserPassword = MD5(Request.Form("UserPassword"))


If CodeIsTrue()=False Then
	alertBox "验证码检验失败!","javascript:history.go(-1)"
End If

Member_Type		= reform("Member_Type")
Reg_IP = get_clientip()

UserID = User_Reg()

Select Case UserID
	   Case 0		Writebr "用户注册失败，请与管理员联系!"
	   Case -9		AlertBox "用户已经注册!","javascript:history.go(-1)"	
	   Case Else	
	   	   	Session("UserName")    = UserName
			Session("Member_Type") = Member_Type
			alertBox "注册成功","Index.asp"
			'Response.Redirect "Index.asp"
			'writebr "注册成功"
			endd

End Select 



'用户注册函数
'注册成功返回大于0的UserID
'失败返回 0
'用户存在 -9
'************************

Function User_Reg()

	UserID = Get_FirstValue("SELECT UserID FROM Member WHERE UserName='"&UserName&"'")
	If UserID<>"" Then 
		User_Reg = -9
		Exit Function 
	End If 

	Sql = "INSERT INTO Member(UserName,UserPassword,Reg_Date,Reg_IP,Member_Type) VALUES("&_
		  "'"&UserName&"'"&_
		  ",'"&UserPassword&"'"&_
		  ",'"&Now()&"'"&_
		  ",'"&Reg_IP&"'"&_
		  ",'"&Member_Type&"'"&_
		  ")"
	User_Reg = Insert_And_ReturnID(Sql,"Member","UserID")
	

End Function 

Public Function CodeIsTrue()

	Dim CodeStr

	CodeStr = reform("code")
	
	If CStr(Session("rndcodes"))=CStr(CodeStr) And Session("rndcodes")<>""   Then
		CodeIsTrue=True
		Session("rndcodes")=empty
	Else
		CodeIsTrue=False
		Session("rndcodes")=empty
	End If
	
End Function

%>